package com.mccken.springframework.factory.support;

import java.util.HashMap;
import java.util.Map;

import com.mccken.springframework.BeansException;
import com.mccken.springframework.factory.config.BeanDefinition;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2022-11-19 23:38
 **/
public class DefaultListableBeanFactory extends AbstractAutowiredCapableBeanFactory implements BeanDefinitionRegistry {
	
	private Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();
	
	@Override
	public BeanDefinition getBeanDefinition(String beanName) throws BeansException {
		BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
		if (beanDefinition == null) {
			throw new BeansException("No bean named '" + beanName + "' is defined");
		}
		return beanDefinition;
	}

	@Override
	public void registerBeanDefinition(String beanName, BeanDefinition beandefinition) {
		beanDefinitionMap.put(beanName, beandefinition);
	}
}
